package com.crane.common.core.exception;


import java.text.MessageFormat;

/**
 * 错误类接口
 *
 * @author zhenxing.pi
 */
public class AppException extends RuntimeException {

    private static final long serialVersionUID = 1L;
    /**
     * 异常代码
     */
    protected String errCode;
    /**
     * 异常代码描述
     */
    protected String errDesc;

    public AppException(String errMessage) {
        super(errMessage);
        this.errDesc = errMessage;
    }

    public AppException(String errCode, String errMessage) {
        super(errMessage);
        this.errCode = errCode;
        this.errDesc = errMessage;
    }

    public AppException(ErrorCode errCode) {
        super(errCode.getErrDesc());
        this.errCode = errCode.getErrCode();
        this.errDesc = errCode.getErrDesc();
    }

    public AppException(String errMessage, Throwable e) {
        super(errMessage, e);
        this.errDesc = errMessage;
    }

    public AppException(String errCode, String errMessage, Throwable e) {
        super(errMessage);
        this.errCode = errCode;
        this.errDesc = errMessage;
    }

    public AppException(ErrorCode errCode, Throwable e) {
        super(errCode.getErrDesc());
        this.errCode = errCode.getErrCode();
        this.errDesc = errCode.getErrDesc();
    }


    public AppException(ErrorCode errCode, Object... replacements) {
        super(MessageFormat.format(errCode.getErrDesc(), replacements));
        this.errCode = errCode.getErrCode();
    }

    public AppException(ErrorCode errCode, Throwable e, Object... replacements) {
        super(MessageFormat.format(errCode.getErrDesc(), replacements), e);
        this.errCode = errCode.getErrCode();
    }

    public String getErrCode() {
        return errCode;
    }

    public String getErrDesc() {
        return errDesc;
    }
}
